﻿using Control.Server;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using TouchSocket.Core;
using TouchSocket.Http;
using TouchSocket.Http.WebSockets;
using TouchSocket.Sockets;

namespace Control.WeSocket
{
    public class SocketHelper
    {

        public WebSocketClient client;
        private Form1 form;
        public SocketHelper(WebSocketClient _client, Form1 _form)
        {
            client = _client;
            form = _form;

        }

        public async Task ConnectAsync()
        {
            await client.SetupAsync(new TouchSocketConfig()
                                 //   .SetRemoteIPHost("ws://192.168.215.98:7789/ws")
                                      .SetRemoteIPHost("ws://192.168.1.18:7789/ws")
                                    .ConfigureContainer(a =>
                                    {
                                        a.AddConsoleLogger();
                                    }).ConfigurePlugins(a =>
                                    {
                                        var plugin = a.Add<WebSocketPlugin>();
                                        plugin.UpdateImageHandler = form.UpdateImageAsync;
                                    }));
            await client.ConnectAsync();
        }
    }
}
